<template>
  <div>
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="loadList">
        <a-row :gutter="24">
          <a-col :span="6">
            <a-form-item>
              <a-input placeholder="操作人名称" v-model="ipagination.createUserName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item>
              <a-select v-model="ipagination.operateType" placeholder="请选择权限">
                <a-select-option
                  v-for="option in operateTypeOptions"
                  :key="option.value"
                  :value="option.value"
                  :allowClear="true"
                  >{{ option.label }}</a-select-option
                >
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item>
              <a-date-picker v-model="ipagination.createTime" placeholder="请选择操作日期" valueFormat="YYYY-MM-DD" />
            </a-form-item>
          </a-col>
          <a-col :span="6">
            <a-form-item>
              <a-button icon="query" @click="loadList">查询</a-button>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        row-key="id"
        :columns="columns"
        :data-source="tableData"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      />
    </div>
  </div>
</template>

<script>
import { getAction } from '@/api/manage'

export default {
  name: 'LibLog',
  components: {},
  props: {
    hteFile: {
      type: Object,
      default: () => {},
    },
    
  },
  data() {
    return {
      operateTypeOptions: [
        { value: 1, label: '签收' },
        { value: 2, label: '下载' },
        { value: 3, label: '收藏' },
         { value: 5, label: '查阅' },
      ],
    parentId:this.$route.params && this.$route.params.c,
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '操作人 ',
          align: 'center',
          dataIndex: 'createUserName',
        },

        {
          title: '操作日期',
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: '操作类型',
          align: 'center',
          dataIndex: 'operateType',
          customRender: (text) => {
            if (text == 1) {
              return '签收'
            } else if (text == 2) {
              return '下载'
            } else if (text == 3) {
              return '收藏'
            }else if (text == 4) {
              return '利用'
            }
            else if (text == 5) {
              return '查阅'
            } else {
              return text
            }
          },
        },
        {
          title: '签收单号',
          align: 'center',
          dataIndex: 'signNo',
        },
        {
          title: '客户端地址',
          align: 'center',
          dataIndex: 'ip',
        }
      ],
      tableData: [],
      dataSource: [],
      /* 分页参数 */
      ipagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0,
        name: '',
      },
      loading: false,
      title: '',
      width: 800,

      disableSubmit: false,
      data: [],
      selectedRowKeys: [],
      rowKeyIndex: -1,
      addVisible: false,
      confirmLoading: false,
      model: { objectType: 1, client: '海芯', objectId: [] },
      validatorRules: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      objData: [],
      fetching: false,
      url: {
        list: '/lib/hteLibLog/list',
      },
      fileId: 0,
    }
  },

  created() {},
  mounted(){
      this.initData()
  },
  methods: {
    initData(){
      debugger
      if(this.parentId == 2){
        let index = this.operateTypeOptions.findIndex(i=>{return i.value == 4})
        if(index  == -1){
          this.operateTypeOptions.push( { value: 4, label: '利用' })
        }
      }
    },
    loadList() {
      
      if (this.hteFile.id) {
        this.ipagination.fileId = this.hteFile.id
        let param = Object.assign({}, this.ipagination)
        delete param.pageSizeOptions
        delete param.showTotal
        getAction(this.url.list, param).then((res) => {
          if (res.success) {
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
            this.tableData = res.result.records
            this.$emit("getTotal",this.ipagination.total)
          } else {
            this.$message.error(res.message)
          }
        })
      }
    },



    handleTableChange(pagination, filters, sorter) {
      // 分页、排序、筛选变化时触发
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field
        this.isorter.order = sorter.order === 'ascend' ? 'asc' : 'desc'
      }
      this.ipagination = pagination
      this.ipagination.pageNo = this.ipagination.current
      this.loadList()
    },

  },
  watch: {
    'hteFile.id': {
      handler: function (newVal, oldVal) {
        console.info(123123)
        if (newVal != oldVal) {
          this.loadList()
        }
      },
    },
  },
}
</script>
